<?php

namespace app\common\model;

/**
 * [Report  信息表]
 * @author [C。]
 * @return html
 */
class Rymsg extends Base
{
    protected $name = 'rymsg';
    /**
     * 根据搜索条件获取列表信息
     */
    public function getlist($map, $from = 0, $size = 5)
    {
        $order = ['r.id' => 'desc'];
        $join1 = [
            ['app_member am1','am1.id = r.fromid'],
        ];
        $join2 = [
            ['app_member am2','am2.id = r.toid'],
        ];
        $result = $this->field('r.id,r.fromid,r.toid,r.content,r.addtime,r.msgid,r.source,am1.username as fromusername,am2.username as tousername')
            ->alias('r')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取总条数
     */
    public function getCount($map)
    {
        $join1 = [
            ['app_member am1','am1.id = r.fromid'],
        ];
        $join2 = [
            ['app_member am2','am2.id = r.toid'],
        ];
        $result = $this->alias('r')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->count();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getlists($map1,$map2, $from = 0, $size = 5)
    {
        $order = ['r.id' => 'desc'];
        $join1 = [
            ['app_member am1','am1.id = r.fromid'],
        ];
        $join2 = [
            ['app_member am2','am2.id = r.toid'],
        ];
        $result = $this->field('r.id,r.fromid,r.toid,r.content,r.addtime,r.msgid,r.source,am1.username as fromusername,am2.username as tousername')
            ->alias('r')
            ->join($join1)
            ->join($join2)
            ->where($map1)
            ->whereOr($map2)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取总条数
     */
    public function getCounts($map1,$map2)
    {
        $join1 = [
            ['app_member am1','am1.id = r.fromid'],
        ];
        $join2 = [
            ['app_member am2','am2.id = r.toid'],
        ];
        $result = $this->alias('r')
            ->join($join1)
            ->join($join2)
            ->where($map1)
            ->whereOr($map2)
            ->count();

        return $result;
    }
}
